﻿using UnityEngine;
using System.Collections;

public class PerkBtn : MonoBehaviour {
    public PerkData pPerkData;

	public int iPositionIndex;
	public bool bEmpty;

    bool m_bInformOn;

	void Start(){
		if(transform.parent.GetComponent<UISprite>())
			GetComponent<UISprite>().depth = transform.parent.GetComponent<UISprite> ().depth + 1;
	}

    public void SetInit(PerkData perkData, int iIndex, PAPER_TYPE Type)
	{
        pPerkData = perkData;
		iPositionIndex = iIndex;
		bEmpty = false;

		if (Type == PAPER_TYPE.APPLICATION_POLICE) {
			if (iPositionIndex == 0)
				transform.localPosition = new Vector3 (3.4f, -10.5f);
			else
				transform.localPosition = new Vector3 (3.4f, -15.5f);
			transform.localScale = new Vector3 (-0.17f, 0.045f);


        }
        else if (Type == PAPER_TYPE.APPLICATION_TECH)
        {
            if (iPositionIndex == 0)
                transform.localPosition = new Vector3(7, -7);
            else
                transform.localPosition = new Vector3(7, -12);
            transform.localScale = new Vector3(-0.17f, 0.045f);


        }
        else
        {
			transform.localPosition = new Vector3 (25, 21 - (iPositionIndex*7));
			transform.localScale = new Vector3(-0.35f, 0.06f);
		}

        GetComponent<UISprite>().color = new Color(150 / 255f, 115 / 255f, 115 / 255f);

	}

    void OnHover(bool isOver)
    {
        if (!bEmpty)
        {

            if (isOver)
            {
                if (transform.parent.name == "ApplicationBtn(Clone)")
                {
                    if (transform.parent.GetComponent<ApplicationBtn>().Selected && !m_bInformOn)
                    {
                        ResourceMgr.GetInstance().CreateInformBox(pPerkData.m_strName, pPerkData.m_strDesc);
                        m_bInformOn = true;
                    }
                }
                else
                {
                    if (!m_bInformOn)
                    {
                        ResourceMgr.GetInstance().CreateInformBox(pPerkData.m_strName, pPerkData.m_strDesc);
                        m_bInformOn = true;
                    }
                }
            }



            if (!isOver && m_bInformOn)
            {
                m_bInformOn = false;
                for (int i = 0; i < GameObject.Find("InformBoxUI").transform.childCount; ++i)
                {
                    Destroy(GameObject.Find("InformBoxUI").transform.GetChild(i).gameObject);
                }
            }

        }
    }

	public void SetEmpty(int iIndex, PAPER_TYPE Type){
		iPositionIndex = iIndex;

        if (Type == PAPER_TYPE.APPLICATION_POLICE)
        {
			transform.localPosition = new Vector3 (3.4f, -15.5f);
			transform.localScale = new Vector3 (-0.17f, 0.045f);
        }
        else if (Type == PAPER_TYPE.APPLICATION_TECH)
        {
            transform.localPosition = new Vector3(7, -12);
            transform.localScale = new Vector3(-0.17f, 0.045f);
        }
        else
        {
			transform.localPosition = new Vector3 (25, 21 - (iPositionIndex*7));
			transform.localScale = new Vector3(-0.35f, 0.06f);
		}

		gameObject.GetComponent<UISprite>().spriteName = "Perk0";
		bEmpty = true;
	}

	void Update(){
	

	}
}
